<?php
namespace Admin\Controller;

use Think\Page;

class OrderController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
        $this->model = M('order');
    }

    public function index()
    {
        $this->display();
    }

    /**
     * 未服务
     * @return [type] [description]
     */
    public function wait()
    {
    	$where = [
    		'status' => 1,
    		'is_pay' => ['gt',1],
    		'shop_id' => SHOP_ID,
    	];

        $count = $this->model
            ->where($where)
            ->count();

        $page = new Page($count, C('PAGE'));

        $list = $order
            ->where($where)
            ->limit($pages->firstRow . ',' . $pages->listRows)
            ->select();

        $status_array = array('取消','接单');
        foreach($list as $k => $vo){
            $list[$k]['is_show'] = $status_array[$vo['is_show']];
        }

        $this->assign('count',$count);
        $this->assign('pages',$pages->show());
        $this->assign('list',$list);
        $this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '订单管理',
            '未服务',
        ]));
        $this->display();
    }

    /**
     * 已服务
     * @return [type] [description]
     */
    public function finsh()
    {
        $where = [
    		'status' => 2,
    		'is_pay' => ['gt',1],
    		'shop_id' => SHOP_ID,
    	];

        $count = $this->model
            ->where($where)
            ->count();

        $page = new Page($count, C('PAGE'));

        $list = $order
            ->where($where)
            ->limit($pages->firstRow . ',' . $pages->listRows)
            ->select();

        $this->assign('count',$count);
        $this->assign('pages',$pages->show());
        $this->assign('list',$list);
        $this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '订单管理',
            '已服务',
        ]));
        $this->display();
    }

    /**
     * 已取消
     * @return [type] [description]
     */
    public function cancel()
    {
        $where = [
    		'status' => 0,
    		'is_pay' => ['gt',1],
    		'shop_id' => SHOP_ID,
    	];

        $count = $this->model
            ->where($where)
            ->count();

        $page = new Page($count, C('PAGE'));

        $list = $order
            ->where($where)
            ->limit($pages->firstRow . ',' . $pages->listRows)
            ->select();

        $this->assign('count',$count);
        $this->assign('pages',$pages->show());
        $this->assign('list',$list);
        $this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '订单管理',
            '已服务',
        ]));
        $this->display();
    }

    /**
     * 已退款
     * @return [type] [description]
     */
    public function refund()
    {
    	$where = [
    		'status' => 3,
    		'is_pay' => ['gt',1],
    		'shop_id' => SHOP_ID,
    	];

        $count = $this->model
            ->where($where)
            ->count();

        $page = new Page($count, C('PAGE'));

        $list = $order
            ->where($where)
            ->limit($pages->firstRow . ',' . $pages->listRows)
            ->select();

        $this->assign('count',$count);
        $this->assign('pages',$pages->show());
        $this->assign('list',$list);
        $this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '订单管理',
            '已服务',
        ]));
        $this->display();
    }

    public function detail()
    {
    	$where = [
    		'order_id' => I('post.order_id','','intval'),
    		'shop_id' => SHOP_ID,
    	];

    	$order_detail = $this->model
    		->where($where)
    		->find();

    	$this->assign('order_detail',$order_detail);
    	$this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '订单管理',
            '已服务',
        ]));
    	$this->display();
    }
}
